package com.zhiyun.test.demo.service;

import com.zhiyun.test.base.service.BaseService;
import com.zhiyun.test.base.util.PropUtil;
import com.zhiyun.test.base.util.ThreadUtil;
import com.zhiyun.test.demo.page.LoginPage;
import org.openqa.selenium.WebDriver;
import org.apache.log4j.Logger;

/**
 * Created by user on 2019-5-27.
 */
public class LoginService extends BaseService{
  private LoginPage loginPage;
  private Logger logger = Logger.getLogger(LoginService.class);
  public LoginService(WebDriver webDriver) {
    super(webDriver);
    loginPage = new LoginPage(webDriver);
  }
  public void login(String username,String password){
    loginPage.setUserName(username);
    loginPage.setPassword(password);
    loginPage.clickLoginBtn();
    ThreadUtil.sleep(1);
    if(loginPage.checkSuccess()){
      logger.info("登录成功");
      String token = storageUtil.getItemFromSessionStorage("token");
      PropUtil.setProp("token.prop","token",token);
    }else {
      logger.info("登录失败");
    }
  }
}
